package com.ljkj.blockpay.ui.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.kongzue.baseokhttp.util.JsonMap;
import com.ljkj.blockpay.R;
import com.ljkj.blockpay.basedata.BaseActivity;
import com.ljkj.blockpay.databinding.ActivityAccountsSecurityBinding;
import com.ljkj.blockpay.presenter.AccountsSecurityPresenter;
import com.ljkj.blockpay.presenter.SecurityInter;
import com.ljkj.blockpay.util.ToggleToActivity;
import com.ljkj.blockpay.widget.ClickListener;

/**
 * 账号与安全页面
 */
public class AccountsSecurityActivity extends BaseActivity<ActivityAccountsSecurityBinding,AccountsSecurityPresenter> implements SecurityInter.SecurityInterView, ClickListener {


    @Override
    public int initContentView() {
        return R.layout.activity_accounts_security;
    }



    @Override
    protected AccountsSecurityPresenter createPresenter() {
        return new AccountsSecurityPresenter(this,this);
    }

    @Override
    protected void init(Bundle savedInstanceState) {

        binding.setOnClick(this::onClick);
        binding.tvTitle.setTitleContent(R.string.safetycenter);
        binding.tvTitle.setLeftBackFinish(this);

    }

    @Override
    protected void initData() {
        super.initData();

        getPresenter().accountSecurity();
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.rl_phone:
                ToggleToActivity.toSFZActivity(this,1);
                break;
            case R.id.rl_email:
                ToggleToActivity.toSFZActivity(this,2);
                break;
            case R.id.rl_loginpwd:
                ToggleToActivity.toChangePasswordActivity(this);
                break;
            case R.id.rl_toset:
                ToggleToActivity.toSFZActivity(this,3);
                break;
            case R.id.rl_tobindGoogle:
                ToggleToActivity.toGoogleVerifierActivity(this);
                break;
        }

    }

    //查询状态
    @Override
    public void securitySuccess(JsonMap jsonMap) {
        String mobile = jsonMap.getString("mobile");
        String email = jsonMap.getString("email");
        boolean loginPwdFlag = jsonMap.getBoolean("loginPwdFlag");
        boolean tradePwdFlag = jsonMap.getBoolean("tradePwdFlag");
        boolean googleAuthFlag = jsonMap.getBoolean("googleAuthFlag");
        if (mobile != null){
            binding.tvApprove.setText(mobile);
        } else {
            binding.tvApprove.setText(getResources().getString(R.string.tobind));
        }
        if (email.equals("")){
            binding.tvEmail.setText(email);
        } else {
            binding.tvEmail.setText(getResources().getString(R.string.tobind));
        }
        if (loginPwdFlag){
            binding.tvAmend.setText(getResources().getString(R.string.verified));
        } else {
            binding.tvAmend.setText(getResources().getString(R.string.unverified));
        }
        if (tradePwdFlag){
            binding.tvToset.setText(getResources().getString(R.string.alsetting));
        } else {
            binding.tvToset.setText(getResources().getString(R.string.tosetting));
        }
        if (googleAuthFlag){
            binding.tvToset.setText(getResources().getString(R.string.albind));
        } else {
            binding.tvToset.setText(getResources().getString(R.string.tobind));
        }


    }
}